class Solution:
    def lengthOfLongestSubstring(self, s: str) -> int:
        length, left = 0, 0
        max_length = len(set(s))
        for right, x in enumerate(s):
            if x in s[left: right]:
                length = max(length, right - left)
                left += s[left:right].index(x) + 1
                if length == max_length:
                    return max(length, len(s)-left)
        return max(length, len(s)-left)


s = "aaaaa"

print(Solution().lengthOfLongestSubstring(s))
